package com.dong.ui.component;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @description: 链接文本
 * @author: 陈瑞东
 * @create: 2021-08-24 15:11
 */
public class LinkLabel extends JLabel {


    private static final Color NORMAL_COLOR = new Color(191,191,191); // 默认字体颜色
    private static final Color HOVER_COLOR = new Color(131, 131, 131); // 默认鼠标悬浮字体颜色

    private Color normalColor = NORMAL_COLOR;
    private Color hoverColor = HOVER_COLOR;

    public LinkLabel() {
        super();
        init();
    }

    public LinkLabel(String text) {
        super(text);
        init();
    }

    public LinkLabel(Icon image) {
        super(image);
        init();
    }

    public LinkLabel(String text, Color normal, Color hover) {
        super(text);
        this.normalColor = normal;
        this.hoverColor = hover;
        init();
    }

    private void init() {
        // 设置文字颜色
        setForeground(normalColor);
        // 设置文字颜色随鼠标移入而改变
        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                super.mouseEntered(e);
                setForeground(hoverColor);
                setCursor(new Cursor(Cursor.HAND_CURSOR));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                super.mouseExited(e);
                setForeground(NORMAL_COLOR);
                setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            }
        });
    }

    public Color getNormalColor() {
        return normalColor;
    }

    public void setNormalColor(Color normalColor) {
        this.normalColor = normalColor;
    }

    public Color getHoverColor() {
        return hoverColor;
    }

    public void setHoverColor(Color hoverColor) {
        this.hoverColor = hoverColor;
    }
}
